package com.billdowney.service.impl.area;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.billdowney.dao.area.ChinaCityDao;
import com.billdowney.dao.area.ChinaCountyDao;
import com.billdowney.dao.area.ChinaProvinceDao;
import com.billdowney.dao.area.ChinaTownDao;
import com.billdowney.dao.area.ChinaVillageDao;
import com.billdowney.entity.area.ChinaCity;
import com.billdowney.entity.area.ChinaCounty;
import com.billdowney.entity.area.ChinaProvince;
import com.billdowney.entity.area.ChinaTown;
import com.billdowney.entity.area.ChinaVillage;
import com.billdowney.service.impl.base.BaseServiceImpl;
import com.billdowney.service.interfaces.area.ChinaAreaService;

/**
 * @Description: 中国区域借口
 * @author: 唐路钧
 * @date: 2018年8月30日 下午8:17:17
 */
@Service
public class ChinaAreaServiceImpl extends BaseServiceImpl<ChinaProvinceDao, ChinaProvince, String>
		implements ChinaAreaService {

	@Autowired
	private ChinaCityDao chinaCityDao;

	@Autowired
	private ChinaCountyDao chinaCountyDao;

	@Autowired
	private ChinaTownDao chinaTownDao;

	@Autowired
	private ChinaVillageDao chinaVillageDao;

	@Resource(type = ChinaProvinceDao.class)
	@Override
	public void setDao(ChinaProvinceDao dao) {
		super.dao = dao;
	}

	@Override
	public void saveOrUpdate(Object object) {
		if (object instanceof ChinaCity) {
			chinaCityDao.save((ChinaCity) object);
		} else if (object instanceof ChinaCounty) {
			chinaCountyDao.save((ChinaCounty) object);
		} else if (object instanceof ChinaProvince) {
			dao.save((ChinaProvince) object);
		} else if (object instanceof ChinaTown) {
			chinaTownDao.save((ChinaTown) object);
		} else if (object instanceof ChinaVillage) {
			chinaVillageDao.save((ChinaVillage) object);
		}
	}

	@Override
	public void deleteAllChinaData() {
		try {
			chinaCityDao.deleteAllInBatch();
			chinaCountyDao.deleteAllInBatch();
			dao.deleteAllInBatch();
			chinaTownDao.deleteAllInBatch();
			chinaVillageDao.deleteAllInBatch();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
